#pragma once

#include"RedBlackTree.h"
namespace zy
{
	template<class k, class v>
	class map
	{
		struct MapKeyOfT
		{
			const k& operator()(const pair<k, v>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<k, pair<const k, v>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<k, pair<const k, v>, MapKeyOfT>::const_Iterator const_iterator;

		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}

		const_iterator begin() const
		{
			return _t.begin();
		}
		const_iterator end() const
		{
			return _t.end();
		}

		pair<iterator, bool> Insert(const pair<k, v>& kv)
		{
			return _t.Insert(kv);
		}

		v& operator[](const k& key)
		{
			pair<iterator, bool> ret = Insert({ key,v() });
			return ret.first->second;
		}
	private:
		RBTree<k, pair<const k,v>, MapKeyOfT> _t;
	};
}